package com.yingside.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class TestDelete {
    public static void main(String[] args) {
        //1.先导入jar包

        //2.导入驱动，jdk1.8之后的版本，j2se程序可以省略，但是建议还是写上
        //com.mysql.cj.jdbc.Driver 这个路径实际就是找到Driver这个类
        //注意该路径是mysql8.0以后的jar包
        //如果是mysql5.7以前的jar，路径是com.mysql.jdbc.Driver
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        Connection conn = null;
        Statement stmt = null;
        String url = "jdbc:mysql://47.108.158.110:3306/j181db";
        String user = "root";
        String password = "123456";

        try {
            //3.获取连接
            conn = DriverManager.getConnection(url,user,password);

            //4.获取stmt对象
            stmt = conn.createStatement();

            //5.执行sql语句
            String sql = "delete from t_teacher where teacher_id=10015";
            //增删改都是对数据库的更新，所以调用的都是executeUpdate方法，返回int的值
            //表示对数据库几行受影响
            int i = stmt.executeUpdate(sql);

            if(i > 0){
                System.out.println("删除成功！");
            }
            else{
                System.out.println("删除失败");
            }

        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }


    }
}
